<?php
include_once("functions/db_manipulate.php");

if (!init()) {
  redirect("?action=login");
}

$galleryResultSet = getLastGalleryImages();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title><?= getMessageByKey("gallery.title") ?></title>

  <link rel="stylesheet" type="text/css" href="css/square.css">
  <link rel="stylesheet" type="text/css" href="css/menu.css">
  <link rel="stylesheet" type="text/css" href="css/common.css">
  <link rel="stylesheet" type="text/css" href="css/gallery.css">
  <link rel="stylesheet" type="text/css" href="css/profile.css">
  <link rel="stylesheet" type="text/css" href="css/navigation.css">
  <script src="resources/jquery.js"></script>
  <script language="JavaScript">
    function customFormSubmit() {
      $('#maximized_navigation').show();
      $('#galimgform').submit();
    }
  </script>

  <meta charset="UTF-8">
</head>

<body class="body">

<?php
include_once("menu.php");
?>

<div id="square">

  <div class="gallerydiv">
    <div class="galleryheader">
      <?= getMessageByKey("gallery.last.header") ?>
    </div>
    <?php
    while ($gallery = mysql_fetch_assoc($galleryResultSet)) {
      ?>
      <div class="galleryimgdiv" onclick="location.href='?action=img&iid=<?= $gallery['id'] ?>'">
        <div class="imageinfo">
          <div class="imageinfotd">
            #<?= $gallery['id'] ?>
          </div>
          <div class="imageinfotd" style="text-align: right;">
            <?= $gallery['time'] ?>
          </div>

        </div>
        <img src="<?= \controller\Config::getPropertyByKey('directory.view.gallery') . $gallery['path'] ?>" class="galleryimg">

        <div class="imageauthorinfo">
          <div class="imageinfotd">
            <?= getTextWithAcronym($gallery['author'], 10) ?>
          </div>
          <div class="imageinfotd" style="text-align: right;">
            <?= $gallery['date'] ?>
          </div>

        </div>
      </div>

    <?php
    }
    ?>

<!--    <div class="archivebutton" onclick="location.href='?action=galarch'">-->
    <!--      --><? //= \controller\ControllerUtil::getMessageByKey("button.gallery.archive") ?>
    <!--    </div>-->

    <form enctype="multipart/form-data" style="width: 70%; margin-left: auto; margin-right: auto"
          accept-charset="UTF-8" action="?action=galimghand" method="post"
          id="galimgform">
      <span style="font-weight: bold"><?= getMessageByKey("gallery.new") ?></span>
      <textarea name="header" id="textarea" rows="1"
                placeholder="<?= getMessageByKey("gallery.new.header.placeholder") ?>"
                required="true"></textarea>
      <textarea name="legend" id="textarea" rows="11"
                placeholder="<?= getMessageByKey("gallery.new.content.placeholder") ?>"></textarea>

      <input type="hidden" name="MAX_FILE_SIZE" value="25000000"/>

      <div style="display: inline-block; width: 100%">
        <div id="fileinputdiv">
          <input name="image" required="true" type="file" accept=".jpg, .png, .jpeg, .gif" id="realfileinput"
                 onclick="$('#galvisdiv').slideDown()">

          <div id="fileinput"><?= getMessageByKey("button.general.images") ?></div>

        </div>


        <div id="commentbutton" onclick="customFormSubmit()">
          <?= getMessageByKey("button.general.continue") ?>
        </div>
        <div id="galvisdiv">
          <?= getMessageByKey("button.new.visible.ask") ?>
          <select class="updateuserinfoinput" name="galvis">
            <option selected value="true">
              <?= getMessageByKey("general.yes") ?>
            </option>
            <option value="false">
              <?= getMessageByKey("general.no") ?>
            </option>
          </select>
        </div>

      </div>
    </form>
  </div>

</div>

<?php
include_once("navigation.php");
?>

</body>
</html>
